/*
 * jpRegistroGestante.java
 *
 * Created on 23 de agosto de 2007, 8:23
 */

package legajopersonal;

/**
 *
 * @author  practicante
 */
public class jPRegistroGestante extends Panel_Legajo {
    
    /** Creates new form jpRegistroGestante */
    public jPRegistroGestante() {
        initComponents();
        this.jrbtnNoGestante.setSelected(true);
        this.jcboTipo_Doc.setVisible(false);
        this.jftfNum_Carta_Medica.setVisible(false);
        this.jLabel1.setVisible(false);
        this.jLabel2.setVisible(false);
        this.jcboTipo_Doc.requestFocus();
        this.setSize(318,174);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jftfNum_Carta_Medica = new javax.swing.JFormattedTextField();
        jcboTipo_Doc = new javax.swing.JComboBox();
        jbtnAceptarGestante = new javax.swing.JButton();
        jbtnCancelarGestante = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jrbtnSiGestante = new javax.swing.JRadioButton();
        jrbtnNoGestante = new javax.swing.JRadioButton();
        this.buttonGroup1.add(this.jrbtnSiGestante);
        this.buttonGroup1.add(this.jrbtnNoGestante);

        jLabel1.setText("Tipo de Documento que acredita la paternidad");

        jLabel2.setText("Doc que acredita la paternidad");

        jftfNum_Carta_Medica.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jftfNum_Carta_MedicaKeyPressed(evt);
            }
        });

        jcboTipo_Doc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboTipo_DocKeyPressed(evt);
            }
        });

        jbtnAceptarGestante.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/options.gif"))); // NOI18N
        jbtnAceptarGestante.setText("Aceptar");
        jbtnAceptarGestante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAceptarGestanteActionPerformed(evt);
            }
        });

        jbtnCancelarGestante.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/undo.gif"))); // NOI18N
        jbtnCancelarGestante.setText("Cancelar");
        jbtnCancelarGestante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCancelarGestanteActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabel3.setText("Gestante");

        jrbtnSiGestante.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jrbtnSiGestante.setText("Si");
        jrbtnSiGestante.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jrbtnSiGestante.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jrbtnSiGestante.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jrbtnSiGestanteItemStateChanged(evt);
            }
        });

        jrbtnNoGestante.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jrbtnNoGestante.setText("No");
        jrbtnNoGestante.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jrbtnNoGestante.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jrbtnNoGestante.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jrbtnNoGestanteItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addGap(78, 78, 78)
                            .addComponent(jrbtnSiGestante)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 267, Short.MAX_VALUE)
                            .addComponent(jrbtnNoGestante)
                            .addGap(27, 27, 27))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel1)
                                .addComponent(jLabel2))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jcboTipo_Doc, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jftfNum_Carta_Medica, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE))
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jbtnAceptarGestante)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtnCancelarGestante)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jrbtnSiGestante)
                    .addComponent(jrbtnNoGestante))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jcboTipo_Doc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jftfNum_Carta_Medica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jbtnCancelarGestante)
                    .addComponent(jbtnAceptarGestante))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jrbtnNoGestanteItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jrbtnNoGestanteItemStateChanged
// TODO add your handling code here:
        if(this.jrbtnNoGestante.isSelected()){
            this.jcboTipo_Doc.setVisible(false);
            this.jftfNum_Carta_Medica.setVisible(false);            
            this.jLabel1.setVisible(false);
            this.jLabel2.setVisible(false);
        }
    }//GEN-LAST:event_jrbtnNoGestanteItemStateChanged

    private void jrbtnSiGestanteItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jrbtnSiGestanteItemStateChanged
// TODO add your handling code here:
        if(this.jrbtnSiGestante.isSelected()){
            this.jcboTipo_Doc.setVisible(true);
            this.jftfNum_Carta_Medica.setVisible(true); 
            this.jLabel1.setVisible(true);
        this.jLabel2.setVisible(true);
        }
    }//GEN-LAST:event_jrbtnSiGestanteItemStateChanged

    private void jbtnAceptarGestanteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarGestanteActionPerformed
// TODO add your handling code here:
        String consulta;
        String tipo;
        String num_carta;
        if(this.jrbtnSiGestante.isSelected()){
            if(this.jftfNum_Carta_Medica.getText().equals("")){
                this.mensaje("Ud. No ha ingresado los datos necesarios");            
            }else{
                try{
                    consulta = "select cod_tipo_doc from tipo_doc_Gestante where desc_doc='"+
                            (String)this.jcboTipo_Doc.getSelectedItem()+"'";
                    tipo =  this.getCliRMI().getObjetoCLIRMI().getCodigo(consulta,this.getID() );
                    num_carta = this.jftfNum_Carta_Medica.getText().trim();
                    this.panFam.setDatosGestante(tipo,num_carta);
                    System.out.println("sss:"+tipo+num_carta);
                    this.cerrarPadre();
                }catch(Exception e){                
                }
            }            
        }else{
            this.panFam.CancelarRegistroGestante();
        }
        
    }//GEN-LAST:event_jbtnAceptarGestanteActionPerformed

    private void jbtnCancelarGestanteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCancelarGestanteActionPerformed
// TODO add your handling code here:
        this.panFam.CancelarRegistroGestante();
        this.cerrarPadre();        
    }//GEN-LAST:event_jbtnCancelarGestanteActionPerformed

    private void jftfNum_Carta_MedicaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jftfNum_Carta_MedicaKeyPressed
// TODO add your handling code here:
        if(evt.getKeyCode()== evt.VK_ENTER){
            this.jbtnAceptarGestante.requestFocus();
        }
    }//GEN-LAST:event_jftfNum_Carta_MedicaKeyPressed

    private void jcboTipo_DocKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboTipo_DocKeyPressed
// TODO add your handling code here:
        if(evt.getKeyCode()== evt.VK_ENTER){
            this.jftfNum_Carta_Medica.requestFocus();
        }
    }//GEN-LAST:event_jcboTipo_DocKeyPressed
    public void LlenarListas(){        
        String Data[];   
        try{
            //tipo de Documentos
            Data =  this.getCliRMI().getObjetoCLIRMI().getDatosLegajo("" +
                    " SELECT     desc_doc" +
                    " FROM         tipo_Doc_Gestante",this.getID());            
            if(!Data.equals(null)){
                for(int i=0;i<Data.length;i++){
                    this.jcboTipo_Doc.addItem(Data[i]);  
                }
            }
        }catch(Exception e){
           mensaje("Error al Llenar Listas en gestante " + e.getMessage());
        }
    }
    public void  mensaje(String msm){
            javax.swing.JOptionPane.showMessageDialog(this, msm);        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JButton jbtnAceptarGestante;
    private javax.swing.JButton jbtnCancelarGestante;
    private javax.swing.JComboBox jcboTipo_Doc;
    private javax.swing.JFormattedTextField jftfNum_Carta_Medica;
    private javax.swing.JRadioButton jrbtnNoGestante;
    private javax.swing.JRadioButton jrbtnSiGestante;
    // End of variables declaration//GEN-END:variables
    
}
